import React, { Component } from 'react'

export default class Methods extends Component {
    constructor(props) {
        super(props)
        this.state = {
            isToggleOn: true
        }
    }

    handleClick = () => {
        console.log('state: ',this.state.isToggleOn)
        this.setState(state => ({
            isToggleOn: !state.isToggleOn
        }))
    }

    render() {
        return (
            <div>
                class fields语法    推荐语法<br/>  
                在回调中使用箭头函数<br/>
                <hr />
                <button onClick={this.handleClick}>
                    {this.state.isToggleOn ? 'ON' : 'OFF'}
                </button>
                {/* <button onClick={() => this.handleClick}>
                    {this.state.isToggleOn ? 'ON' : 'OFF'}
                </button> */}
            </div>
        )
    }
}